package com.uit.smarttool.activity;


import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Toast;

public class ProgressBarActivity extends Activity {
	
	String message = "";
	String title = "";
	Message msg;
	ProgressDialog progressBar;
	private int progressBarStatus = 0;
	protected Handler progressBarHandler = new Handler()
	{
		public void handleMessage(Message msg)
		{
		  if(msg.what==0)
		  {
			  if(message != null)
				  Toast.makeText(getApplicationContext(),message,2000).show();
		  }

		}
	};
		
	
	public void addprogressbar(Context context) { 
		
			// prepare for a progress bar dialog
			progressBar = new ProgressDialog(context);
			progressBar.setCancelable(true);
			progressBar.setMessage(title);
			progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
			progressBar.setProgress(0);
			progressBar.setMax(100);
			progressBar.show();
 
			//reset progress bar status
			progressBarStatus = 0; 
 
			new Thread(new Runnable() {
			  public void run() {
				while (progressBarStatus < 100) {
 
				  // process some tasks
				  progressBarStatus = doWork(); 
 
				  // Update the progress bar
				  progressBarHandler.post(new Runnable() {
					public void run() {
					  progressBar.setProgress(progressBarStatus);
					}
				  });
				}
 
				// ok, file is downloaded,
				if (progressBarStatus >= 100) {
 					
					// close the progress bar dialog
					progressBar.dismiss();
				}
			  }
		       }).start();                
 
    }
	
	public int doWork()
	{
		msg = progressBarHandler.obtainMessage();
        msg.arg1 = 1;
		_doWork();
		return 100;
	}
	
	public void _doWork()
	{
		
	}

}
